import java.util.HashMap;
import java.util.Map;


public class Leetcode2437 {
    private static final Map<String, Integer> HH_COUNT = new HashMap<>();
    private static final Map<String, Integer> MM_COUNT = new HashMap<>();

    static {
        HH_COUNT.put("?0", 3);
        HH_COUNT.put("?1", 3);
        HH_COUNT.put("?2", 3);
        HH_COUNT.put("?3", 3);
        HH_COUNT.put("?4", 2);
        HH_COUNT.put("?5", 2);
        HH_COUNT.put("?6", 2);
        HH_COUNT.put("?7", 2);
        HH_COUNT.put("?8", 2);
        HH_COUNT.put("?9", 2);
        HH_COUNT.put("0?", 10);
        HH_COUNT.put("1?", 10);
        HH_COUNT.put("2?", 4);
        HH_COUNT.put("??", 24);
    }

    static {
        MM_COUNT.put("?0", 6);
        MM_COUNT.put("?1", 6);
        MM_COUNT.put("?2", 6);
        MM_COUNT.put("?3", 6);
        MM_COUNT.put("?4", 6);
        MM_COUNT.put("?5", 6);
        MM_COUNT.put("?6", 6);
        MM_COUNT.put("?7", 6);
        MM_COUNT.put("?8", 6);
        MM_COUNT.put("?9", 6);
        MM_COUNT.put("0?", 10);
        MM_COUNT.put("1?", 10);
        MM_COUNT.put("2?", 10);
        MM_COUNT.put("3?", 10);
        MM_COUNT.put("4?", 10);
        MM_COUNT.put("5?", 10);
        MM_COUNT.put("??", 60);
    }

    public int countTime(String time) {
        int count = 1;
        if (time.charAt(0) == '?'||time.charAt(1) == '?') {
            count *= HH_COUNT.get(time.substring(0, 2));
        }
        if (time.charAt(3) == '?'||time.charAt(4) == '?') {
            count *= MM_COUNT.get(time.substring(3, 5));
        }

        return count;
    }
}

